package cn.fntop.interceptor;

import cn.fntop.constant.TenantConstants;
import cn.fntop.context.TenantContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

/**
 * 处理feign调用时租户传递
 */
@Slf4j
public class FeignTenantInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        if (TenantContextHolder.getTenantId() == null) {
            log.info("TenantId is null,租户ID为空，feign拦截器 >> 跳过");
            return;
        }
        template.header(TenantConstants.TENANT_ID, TenantContextHolder.getTenantId().toString());
    }

}
